package com.zhuang.designpattern.memento;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.*;

import java.util.Date;

/**
 * description: Test
 * date: 2022/9/19 16:13
 * author: Zhuang
 * version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(Test.class);
        Admin admin = new Admin();
        ConfigOriginator configOriginator = new ConfigOriginator();
        configOriginator.setConfigFile(new ConfigFile("1000001", "配置内容A=哈哈", new Date(), "康小庄"));
        admin.append(configOriginator.saveMemento()); // 保存配置
        configOriginator.setConfigFile(new ConfigFile("1000002", "配置内容A=嘻嘻", new Date(), "康小庄"));
        admin.append(configOriginator.saveMemento()); // 保存配置
        configOriginator.setConfigFile(new ConfigFile("1000003", "配置内容A=么么", new Date(), "康小庄"));
        admin.append(configOriginator.saveMemento()); // 保存配置
        configOriginator.setConfigFile(new ConfigFile("1000004", "配置内容A=嘿嘿", new Date(), "康小庄"));
        admin.append(configOriginator.saveMemento()); // 保存配置
        configOriginator.getMemento(admin.undo());   // 历史配置(回滚)
        logger.info("历史配置(回滚)undo：{}", JSON.toJSONString(configOriginator.getConfigFile()));
        configOriginator.getMemento(admin.undo()); // 历史配置(回滚)
        logger.info("历史配置(回滚)undo：{}", JSON.toJSONString(configOriginator.getConfigFile()));
        configOriginator.getMemento(admin.redo()); // 历史配置(前进)
        logger.info("历史配置(前进)redo：{}", JSON.toJSONString(configOriginator.getConfigFile()));
        configOriginator.getMemento(admin.get("1000002")); // 历史配置(获取)
        logger.info("历史配置(获取)get：{}", JSON.toJSONString(configOriginator.getConfigFile()));

    }
}
